<?php

class GetChilds extends CWidget {

    public $widgetID = 'first-widget';
    public $updatedHidden;

    public function run() {
        $this->render('getChilds', array('widgetID' => $this->widgetID));
    }

    public function getDropdownItems($level = 0) {
        $query = "SELECT \"pageId\", \"pageTitle\", \"pageUrl\" FROM {{pages}} WHERE \"pageParent\" = 0";
        $models = Yii::app()->db->createCommand($query)->queryAll(true);
        $select = '<select name="pageParent" parent="0" id="source" style="width:40%" class="get-child ' . $this->widgetID . '">';
        $select .='<option value="0">нет</option>';
        foreach ($models as $model)
            $select .='<option value=\'' . json_encode(array('id' => $model['pageId'], 'url' => $model['pageUrl'])) . '\'>' . $model['pageTitle'] . '</option>';

        return $select .='</select>';
    }

}
